package com.cnc.dao;

import com.cnc.pojo.Course;
import com.cnc.pojo.User;
import com.cnc.utils.PageUtil;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CourseMapper {
    @Select("select * from course where courseName like (concat('%',#{search},'%')) and courseType like (concat('%',#{type},'%'))  limit #{pu.off},#{pu.len}")
    List<Course> getCourseList(@Param("pu")PageUtil pu, @Param("search") String search,@Param("type") String type);

    @Select("select count(*) from course where courseName like (concat('%',#{search},'%')) and courseType like (concat('%',#{type},'%'))")
    int getCountRows(@Param("search") String search,@Param("type") String type);

    @Select("select * from course where cid = #{id}")
    Course getCourseById(@Param("id") int id);

    @Update("update course set courseImage=#{url} where cid=#{id}")
    int UpdateImgById(@Param("id")int id,@Param("url")String url);

    @Update("update course set courseName=#{c.courseName},descs=#{c.descs},courseType=#{c.courseType},courseImage=#{c.courseImage},courseVideo=#{c.courseVideo},coursePrice=#{c.coursePrice},status=#{c.status},createTime=#{c.createTime} where cid=#{c.cid}")
    int updateCourse(@Param("c")Course c);

    @Insert("insert into course(courseName,descs,courseType,courseImage,courseVideo,coursePrice,status,createTime) values(#{c.courseName},#{c.descs},#{c.courseType},#{c.courseImage},#{c.courseVideo},#{c.coursePrice},#{c.status},#{c.createTime})")
    int addCourse(@Param("c")Course c);

    @Delete("delete from course where cid=#{cid}")
    int delCourseById(@Param("cid")int id);

    @Select("select cid,courseName from course")
    List<Course> getAllCourse();
}
